
import { Component } from 'react'
import store from './store'
import * as Action from './action/actionCreator'

class App extends Component {

  constructor(){
    super()
    //获取store 初始值
    this.state = { count: store.getState() }
    store.subscribe(this.syncState)
  }

  
  syncState = ()=>{
    this.setState({count: store.getState()})
  }
  
  increament = () => {
    // this.setState(prestate => ({ count: prestate.count + 1 }))
    store.dispatch(Action.increamentAction())
  }
  decreament = () => {
    store.dispatch(Action.decreamentAction())
  }

  render() {
    return (
      <p>
        Clicked : {this.state.count } times
        <button onClick={this.increament}>+</button>
        <button onClick={this.decreament}>-</button>
      </p>
    )
  }
}

export default App;
